

/******************************************************************************************
Every instance of this class is a normal/abnormal trajectory of a particular scene. Each
trajectory is defined as a sequence of zones/areas and a set of constraints.  

Attributes:
1)id: trajectory identificator.
2)v_zones: sequence of zones/areas. This vector contains the identificators of the zones
belonging to sequence.
3)v_roles: list of roles which are allowed to follow a trajectory.
4)maximum_time: maximum time to finish the trajectory measured in milliseconds.
5)v_allowed_intervals: times intervals in which an object is allowed to follow the trajectory 
 ******************************************************************************************/

import java.util.Vector;
class Trajectory{
	
    protected String id;
    protected Vector<String> v_zones;
    protected Vector<String> v_roles;
    protected Vector<TimeInterval> v_allowed_intervals;
    protected long maximum_time;
    
    public Trajectory(String id){
	this.id = id;
	v_zones = new Vector();
	v_roles = new Vector();
	v_allowed_intervals = new Vector();
    }

    public String getId() {return this.id;}
    public Vector<String> getRoles(){return this.v_roles;}
    public Vector<TimeInterval> getIntervals(){return this.v_allowed_intervals;}
    
    public void addZone(String z){
	this.v_zones.addElement(z);
    }

    public long getMaximumTime(){return this.maximum_time;}

    public String nextZone(String z){
	int index = this.v_zones.indexOf(z);
	if(index == -1 || index == this.v_zones.size()-1) return null;
	else return this.v_zones.elementAt(index+1);
    }
    
    public String getBeginningArea(){
	return this.v_zones.elementAt(0);
    }
    
    public void addTimeInterval(TimeInterval ti){
	this.v_allowed_intervals.addElement(ti);
    }
    
    public void setMaximunTime(String seconds){
	
	this.maximum_time = Long.parseLong(seconds)*1000;		
    }
    public void addZoneToSequence(String zone){
	this.v_zones.add(this.v_zones.size()-1, zone);
    }
    public void addRole(String role){
	this.v_roles.addElement(role);
    }

    public String toString(){
	String cadena = "Name:"+this.id+"\n";
	cadena += "Roles:";
	for(int i=0; i<this.v_roles.size();i++)
	    cadena += v_roles.elementAt(i)+", ";
	cadena += "\nSequence:";
	for(int i=0; i<this.v_zones.size();i++)
	    cadena += v_zones.elementAt(i)+", ";
		cadena +="\n:Intervals:\n";
		for(int i=0; i<this.v_allowed_intervals.size();i++){
		    TimeInterval ti = (TimeInterval) this.v_allowed_intervals.elementAt(i);
		    cadena += "ID: " + ti.getId()+"\n";
		    cadena += ti.toString()+"\n"; 
		}
		
		cadena +="MAX duration: " + this.maximum_time;
		return cadena;
    }//end toString
}//end class
